package com.xmy.cultivate.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.xmy.cultivate.entity.SenateDepart;
import com.xmy.cultivate.entity.SenateDepartProjects;
import com.xmy.cultivate.service.ISenateDepartProjectsService;
import com.xmy.cultivate.service.ISenateDepartService;
import com.xmy.cultivate.util.Code;
import com.xmy.cultivate.util.Result;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author hpiggy
 * @since 2025-04-17
 */
@RestController
@RequestMapping("/api/senateDepartProjects")
public class SenateDepartProjectsController {
    @Autowired
    ISenateDepartProjectsService iSenateDepartProjectsService;

    @Autowired
    ISenateDepartService iSenateDepartService;

    @GetMapping("")
    @ApiOperation("获取项目")
    public Result getSenateDepartList() {

        // 获取所有部门
        List<SenateDepart> senateDepartList = iSenateDepartService.list(new QueryWrapper<SenateDepart>().eq("status", 1));
        for (SenateDepart senateDepart : senateDepartList) {
            QueryWrapper wrapper = new QueryWrapper<>();
            wrapper.select("*,getDictName ( projects_id, 28 ) AS projects_name");
            wrapper.eq("senate_depart_id", senateDepart.getId());
            senateDepart.setSenateDepartProjectsList(iSenateDepartProjectsService.list(wrapper));
        }

        return new Result(Code.OK, senateDepartList, Code.GET_OK_MSG);
    }
}
